<template>
  <div>
    <el-card style="padding:0 200px 0;">
      <el-row>
        <el-col :span="20">
          <h2>{{ shopcart.name }}</h2>
        </el-col>
        <el-col class="container">
          <ul id="header" :span="4">
            <li>概述页</li>
            <li>参数页</li>
            <li>客服咨询</li>
            <li>用户评价</li>
          </ul>
        </el-col>
      </el-row>
    </el-card>
    <div class="main">
      <div class="left">
        <img :src="shopcart.goodsImgUrl" alt="">
      </div>
      <div class="right">
        <h2>{{ shopcart.name }}</h2>
        <div class="ms">
          <span><a style="color:red;">[ 新书出售领卷可优惠50元 ]</a>官方出品必为精品 </span>
          <div class="price">
            <span class="one">价格:</span>
            <span class="two">￥<i>{{ shopcart.price }}</i><del>￥<i>{{ (shopcart.price*1.5).toFixed(2)}}</i></del></span>
          </div>
          <div class="version">
            <div class="one">版本选择</div>
            <ul id="veselect">
              <li v-for="(item, index) in versionlist" :key="index" :class="flag == index ? 'convert1' : ''"
                @click="chooseAlert(index)">{{ item }}</li>
            </ul>
            <ul class="quantity">
              <div class="two">数量</div>
              <el-input-number v-model="num1" @change="handleChange" :min="1" :max="10" label="描述文字"></el-input-number>
            </ul>
            <div class="store">
              <span>总销量:</span>
              <li>18</li>
            </div>
            <div class="button">
              <el-button type="primary" @click="backMain()">返回主页</el-button>
              <el-button type="danger">购买</el-button>
              <el-button style=" background-color:deepskyblue" icon="el-icon-share"></el-button>
            </div>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>
   
<script>
// import bus from '@/bus.js'

export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: 'shopdetail',
  data() {
    return {
      shopcart: {},
      //计数器
      num1: 1,
      //书籍集合
      versionlist: ['第一版', '第二版', '第三版'],

      //被点击之后要换的样式类名
      flag: 0,
      goodsId: this.$route.params.id
    }
  },
  created() {

    this.getshopDetail();
    console.log(this.goodsId);
  },

  methods: {
    //根据id查询当前商品详情
    getshopDetail() {
      this.$API.getGoodsById(this.goodsId).then(res => {
        if (res.code === "200") {
          if (res.data.name.length > 45) {
            let length = res.data.name.lastIndexOf('）')
            if (length == -1) {
              length = res.data.name.lastIndexOf(')')
            }
            res.data.name = res.data.name.substring(0, length + 1)
          }


          console.log(res.data.name);
          this.shopcart = res.data
        }
        console.log(this.shopcart);
      })
    },
    //查询指定id商品数据
    chooseAlert(index) {
      this.flag = index
    },

    //修改商品数量
    handleChange(value) {
      console.log(value);
    },
    backMain() {
      this.$router.push('/front')
    }
  }
}
</script>
<style lang="less" scoped>
.main {
  // width: 1400px;
  margin-top: 50px;
  display: flex;
  justify-content: space-between;

  .left {
    padding: 50px 0 0 300px;

    img {
      width: 400px;
      height: 450px;
      border: 1px solid blue;
    }
  }

  .right {
    margin-right: 210px;

    .button {
      margin-top: 20px;
    }

    .version {
      margin-top: 20px;

      .one {
        margin-bottom: 20px;
        font-size: 18px;
      }

      ul {
        display: flex;

        li {
          background-color: rgba(128, 128, 128, 0.276);
          color: gray;
          margin-right: 15px;
          font-size: 22px;
          width: 100px;
          height: 40px;
          padding: 5px;
          text-align: center;
          cursor: pointer;
        }

        .convert1 {
          background-color: rgba(255, 81, 0, 0.727);
          color: white;

        }
      }
    }

    .store {
      margin-top: 60px;
      display: flex;

      li {
        list-style: none;
        line-height: 30px;
        margin-left: 10px;
        color: red;
      }
    }

    .quantity {
      margin-top: 20px;
      position: relative;

      .two {
        margin-bottom: 20px;
        font-size: 18px;
      }

      .el-input-number {
        margin-top: 40px;
        position: absolute;
        left: 0;
      }
    }

    .ms {
      margin-top: 20px;

      span {
        font-size: 20px;
      }

      .price {
        height: 60px;
        margin-top: 20px;
        padding-top: 18px;
        padding-left: 15px;
        background-color: rgba(255, 157, 0, 0.095);

        .one {
          font-size: 18px;
          color: gray;
        }

        .two {
          color: red;
          font-size: 20px;
          font-weight: 600;
          margin-left: 10px;

          del {
            margin-left: 5px;
            font-size: 17px;
            font-weight: normal;
            color: gray;
            font-style: italic;
          }

          i:first {
            font-style: normal;

          }
        }

      }

      a {
        margin-right: 15px;
      }

      a:hover {
        text-decoration: underline;
        cursor: pointer;
      }
    }
  }
}

.container {
  margin-top: 15px;


}

.el-row {
  width: 100%;
  padding: 15px 0;
  display: flex;
  justify-content: space-between;

}

#header {
  display: flex;
  float: right;

  li {
    height: 10px;
    line-height: 10px;
    border-right: 1px solid gray;
    padding-right: 10px;
    padding-left: 10px;

  }

  li:last-child {
    border-right: 0
  }


  li:hover {
    color: red;
    cursor: pointer;
  }
}
</style>